package com.mlody.auction;

import java.util.HashMap;

import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.packet.Message;
import org.junit.runner.RunWith;
import static org.mockito.Mockito.*;

import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import com.mlody.AuctionEventListener;

@RunWith(MockitoJUnitRunner.class)
public class AuctionMessageTranslator implements MessageListener {

    AuctionEventListener listener;

    public AuctionMessageTranslator(String string, AuctionEventListener listener) {
	this.listener = listener;
    }

    public void processMessage(Chat chat, Message message) {
	AuctionEvent event = AuctionEvent.from(message.getBody());
	String eventType = event.type();
	if ("CLOSE".equals(eventType)) {
	    listener.auctionClosed();
	}
	if ("PRICE".equals(eventType)) {
	    listener.currentPrice(event.currentPrice(), event.increment());
	}
    }

    

}
